const AccessTokenKey = 'ACCESS_TOKEN'
const RefreshTokenKey = 'REFRESH_TOKEN'

// 获取token
export const getAccessToken = () => {
    // 此处与TokenKey相同，此写法解决初始化时Cookies中不存在TokenKey报错
    return sessionStorage.getItem(AccessTokenKey)
        ? sessionStorage.getItem(AccessTokenKey)
        : sessionStorage.getItem('ACCESS_TOKEN')
}

// 刷新token
export const getRefreshToken = () => {
    return sessionStorage.getItem(RefreshTokenKey)
}

// 设置token
export const setToken = (token) => {
    sessionStorage.setItem(RefreshTokenKey, token)
    sessionStorage.setItem(AccessTokenKey, token)
}

// 删除token
export const removeToken = () => {
    sessionStorage.clear()
}
